package com.example.javalib.skill;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class reflection {
/*
    public static void main(String[] args) {
        try {
            Class<?> clazz = Class.forName("com.example.javalib.skill.test01");
            //获取本类的所有方法，存放入数组
            Method[] methods = clazz.getDeclaredMethods();
            for (Method method : methods) {
                System.out.println("方法名："+method.getName());
                //获取本方法所有参数类型，存入数组
                Class<?>[] getTypeParameters = method.getParameterTypes();
                if(getTypeParameters.length==0){
                    System.out.println("此方法无参数");
                }
                for (Class<?> class1 : getTypeParameters) {
                    String parameterName = class1.getName();
                    System.out.println("参数类型："+parameterName);
                }
                System.out.println("****************************");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

*/
/*————————————————
    版权声明：本文为CSDN博主「wal1314520」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
    原文链接：https://blog.csdn.net/wal1314520/article/details/78131881/
    */


 public static void main(String[] args)  {
     try {


        Class<?> clazz = Class.forName("com.example.javalib.skill.test01");
        Method method[] = clazz.getDeclaredMethods();
        for (int i = 0; i < method.length; ++i) {
            Class<?> returnType = method[i].getReturnType();
            Class<?> para[] = method[i].getParameterTypes();
            int temp = method[i].getModifiers();
            System.out.print(Modifier.toString(temp) + " ");
            System.out.print(returnType.getName() + "  ");
            System.out.print(method[i].getName() + " ");
            System.out.print("(");
            for (int j = 0; j < para.length; ++j) {
                System.out.print(para[j].getName() + " " + "arg" + j);
                if (j < para.length - 1) {
                    System.out.print(",");
                }
            }
            Class<?> exce[] = method[i].getExceptionTypes();
            if (exce.length > 0) {
                System.out.print(") throws ");
                for (int k = 0; k < exce.length; ++k) {
                    System.out.print(exce[k].getName() + " ");
                    if (k < exce.length - 1) {
                        System.out.print(",");
                    }
                }
            } else {
                System.out.print(")");
            }
            System.out.println();
        }
    }catch (ClassNotFoundException e)    {
         System.out.println("ClassNotFoundException："+e.getMessage());
     }
     catch (Exception e)    {
         System.out.println("Exception："+e.getMessage());
     }
 }


}

class test01 {
    public test01(){
        System.out.println("我是tset01");
    }
    private void t1(){}
    public void t2(String sss){}
    public void t3(Integer integer,Boolean boo,test02 t){}
}

class test02{}